<?php
function showNavigation($file){
	
	$links=NULL;
	switch($file){
	
		case 'home':
			$links[] = ["display"=>"home","href"=>""];
		break;
		
		case 'payment':
			$links[] = ["display"=>"Payment","href"=>""];
		break;
		
		case 'summary':
			$links[] = ["display"=>"Summary","href"=>""];
		break;
		
		case 'memberDetails':
			$links[] = ["display"=>"Member","href"=>""];
		break;
		
		
	}
	$navBuildHtml="<i style='color:#00BA8B;' class='icon-large icon-home'></i> > ";
		foreach($links as $v){
			$href="href={$v["href"]}";
			$style="style=text-decoration:underline;";
			if($v['href']==""){
				$href='nohref';
				$style="style=text-decoration:underline";
			}
			$display=$v["display"];
			$separator = ($v==end($links)) ? "" : " <span style='padding:5px'> > </span> ";
			$class=($v==end($links)) ? "active" : "";
			$navBuildHtml.="<li class='$class'><a {$href} {$style} title='{$display}'> {$display} </a> ".$separator."</li>";
		}
	$html='<div class="span12"><ol class="breadcrumb">';
	$html.=$navBuildHtml;
	$html.='</ol></div>';
	echo $html;

}

// payment template
function paymentTemplate($mem_list,$currentDate){
	$year_month=formatDate($currentDate, "Ym");
	$mem_select="<select name=\"data[mem_id]\" for=\"Payment Made By\" id=\"member_selection\"	class=\"required \">";
	$mem_select.="<option value=\"\">Select</option>";
	foreach($mem_list as $members){
		$mem_select.=<<<EOT
			<option value="{$members['id']}"> {$members['name']} </option>
EOT;
	}
	$mem_select.="</select>";
	
	$fref=md5(PAYMENT_RECIEVED);
	$formToRecievePayment=<<<EOT
		<script>
			$(document).ready(function(){
				$('#dateOfPaymentRecieved').datetimepicker({
					timepicker:false,
					formatDate:'Y-m-d',
					format:'Y-m-d'
				});
			});
		</script>
		<form id="recieve_payment" method="POST" class="form-horizontal">
			<input type="hidden" id="transactionDetails" name="data[transactionDetails]" />
			<input type="hidden"  name="fref" value="{$fref}" />
			<fieldset>
				<legend>Payment Recieved</legend>
				<input type="hidden" name="data[year_month]" value="{$year_month}" />
				<div class="control-group">											
					<label class="control-label" >Payment Made By</label>
					<div class="controls">
						{$mem_select}
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" >Mode Of Payment</label>
					<div class="controls">
						
						<select class="required" name="data[mode_of_payment]" for="Mode Of Payment" >
							<option value="">Select</option>
							<option value="cash"> Cash  </option>
							<option value="bank"> Bank </option>
						</select>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" >Type Of Payment</label>
					<div class="controls">
						<select name="data[payment_type]" for="Type Of Payment" class="required">
							<option value="">Select</option>
							<option value="maintenance"> Maintenance  </option>
							<option value="adjustment"> Adjustment  </option>
							<option value="others"> Others </option>
						</select>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div style="display:none" id="dueAmtBrkUpDiv" class="control-group">											
					<label class="control-label" >Total amount due</label>
					<div class="controls">
						<table border="1" id="dueAmtBrkUpTbl">
						
						<tr>
							<th style="text-align:left; padding:5px">This Month Maintenance</th>
							<td style="text-align:right; padding:10px"  id="curntMaintAmt"></td>
						</tr>
						
						<tr>
							<th style="text-align:left; padding:5px"><span style="padding:5px">+</span> Additional Charges</th>
							<td style="text-align:right; padding:10px" id="additionalCharges"></td>
						</tr>										
						<tr>
							<th style="text-align:left; padding:5px"><span style="padding:5px">+</span>Previous Dues</th>
							<td style="text-align:right; padding:10px" id="previousDue"></td>
						</tr>
						<tr>
							<th style="text-align:left; padding:5px"><span style="padding:5px">-</span>Amount Already Payed for this month</th>
							<td style="text-align:right; padding:10px" id="amtAlreadyPayed"></td>
						</tr>
						<tr>
							<th style="text-align:left; padding:5px">Total Amt Due for this month</th>
							<td style="text-align:right; padding:10px" id="total"></td>
						</tr>
						
						</table>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" >Total Amount Payed</label>
					<div class="controls">
						<input class="span2 numeric required" for="Total Amount PayedS" name="data[amt_payed]" /> 
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				<div class="control-group">											
					<label class="control-label" >Date of receipt</label>
					<div class="controls">
						<input name="data[dateOfPaymentRecieved]" class="span2 required"  id="dateOfPaymentRecieved" />
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" >Note</label>
					<div class="controls">
						<textarea name="data[note]"></textarea>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label" ></label>
					<div class="controls">
						<input type="submit" value="submit" />
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
			<fieldset>
		</form>
EOT;

	$fref=md5(PAYMENT_MADE);
	$formToMakePayment=<<<EOT
		<script>
			$(document).ready(function(){
				$('#dateOfPaymentMade').datetimepicker({
					timepicker:false,
					formatDate:'Y-m-d',
					format:'Y-m-d'
				});
			});
		</script>
		<form id="make_payment" method="POST" class="form-horizontal">
			<input type="hidden"  name="fref" value="{$fref}" />
			<fieldset>
				<legend>Payment Made</legend>
				<div class="control-group">											
					<label class="control-label" >Payment Made To</label>
					<div class="controls">
						<input name="data[payedTo]" type="text" class="class2"/>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				<div class="control-group">											
					<label class="control-label" >Payment Made Type</label>
					<div class="controls">
						<select id="selectTypeOfPaymentMake" for="Type Of Payment" name="data[selectTypeOfPaymentMake]" class="span2 required ">
							<option value="">Select</option>
							<option value="sweeper">Sweeper</option>
							<option value="electric">Electric Bill</option>
							<option value="garbage_cleaner">Garbage Cleaner</option>
							<option value="lift">Lift</option>
							<option value="repare">Repare</option>
							<option value="others">Others</option>

						</select>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				<div class="control-group">											
					<label class="control-label" >Amount Payed</label>
					<div class="controls">
						<input type="text" name="data[amount]" for="amount payed" class="class2 numeric required"/>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<!--
				<div class="control-group">											
					<label class="control-label" >Due (if any)</label>
					<div class="controls">
						<input type="text" name="data[due]" for="Due" class="class2 numeric"/>
					</div> 													
				</div> 
				-->
				
				<div class="control-group">											
					<label class="control-label" >Date Of Payment</label>
					<div class="controls">
						<input id="dateOfPaymentMade" for="Date Of Payment" type="text" name="data[dateOfPayment]" class="class2 required"/>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				<div class="control-group">											
					<label class="control-label" >Note</label>
					<div class="controls">
						<textarea name="data[note]"></textarea>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
			</fieldset>
			<div class="control-group">											
					<label class="control-label" ></label>
					<div class="controls">
						<input type="submit" value="submit" />
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
			</fieldset>
		</form>
EOT;
	$extraCollectionForm=extraCollectionForm();

	$html=<<<EOT
	<div class="span12">
		<div class="widget ">
			<div class="widget-content">	
				<div class="tabbable">
				<ul class="nav nav-tabs">
				  <li class="active">
					<a href="#recievePayment" data-toggle="tab">Receive Payment</a>
				  </li>
				  <li ><a href="#makePayment" data-toggle="tab">Make Payment</a></li>
				  <li ><a href="#extraCollectionForm" data-toggle="tab">Extra Collection</a></li>
				</ul>
				
				<br>
				
					<div class="tab-content">
						<div class="tab-pane active" id="recievePayment">
				
							{$formToRecievePayment}
				
						</div>
						
						<div class="tab-pane" id="makePayment">
							{$formToMakePayment}
						</div>
						<div class="tab-pane" id="extraCollectionForm">
							{$extraCollectionForm}
						</div>
						
					</div>
				  
				  
				</div>
				
			</div> <!-- /widget-content -->
				
		</div> <!-- /widget -->
		
	</div> <!-- /span8 -->
	
EOT;
	echo $html;

}

function showDueChart($memList,$currentDate){
	$finalArray=NULL;
	if($memList==NULL) return false;
	$month_year=formatDate($currentDate,"Ym");
	$html="";
	foreach($memList as $v){
		$html.="<tr>";
		$html.="<td>".$v["name"]."</td>";
		$html.="<td>".Members::getDueAmmount($v["id"],$month_year)."</td>";
		$html.="</tr>";
		
	}
	$html=<<<EOT
	<div class="span4">
		<div class="widget widget-nopad">
			<div class="widget-header">
				<h3>Payments Not Yet Received </h3>
			</div>
			<div class="widget-content">						
				<table class="table" >
					<tr>
						<th>Due From </th>
						<th>Total Amt Due </th>
					</tr>
					{$html}
				</table>
			</div>
		</div>
	</div>
	<div class="span4">
		<div class="widget widget">
			<div class="widget-header">
				<h3>Refresh Due Chart For This Month </h3>
			</div>
			<div class="widget-content">						
				<input id="refreshDueChart" class="button btn-primary" type="button" value="refresh" />
			</div>
		</div>
	</div>
	<br style="clear:both">
	
EOT;

	echo $html;

}

function showPaymentsMade($paymentList,$heading=NULL){
	if($paymentList==NULL) return;
	$html="";
	foreach($paymentList as $v){
		$html.="<tr>";
		$html.="<td>".$v["payment_to"]."</td>";
		$html.="<td>".$v["type"]."</td>";
		$html.="<td>".$v["total_amt_payed"]."</td>";
		$html.="<td>".$v["note"]."</td>";
		$html.="<td>".$v["date_of_payment"]."</td>";
		$html.="</tr>";
		
	}
	$html=<<<EOT
	
	<div class="span6">
		<div class="widget widget-nopad">
			<div class="widget-header">
				<h3>{$heading} </h3>
			</div>
			<div class="widget-content">						
				<table class="table" >
					<tr>
						<th>Payment To </th>
						<th>Type Of Payment </th>
						<th>Amount Payed </th>
						<th>Note </th>
						<th>Date of payment </th>
					</tr>
					{$html}
				</table>
			</div>
		</div>
	</div>
	
EOT;

	echo $html;

}

function showListOfUsers($memList,$id,$month_year){
	$html="";
	foreach($memList as $v){
		$clr=$v['id']==$id ? "color:#FFFFFF; background-color:#00BA8B" : "";
		$html.="<span style=\"display:inline-block;padding:5px;\" > <a style=\"padding:5px;{$clr}\" href=\"?id={$v['id']}&month_year={$month_year}\">{$v['name']}</a> </span>";
	}
	$html=<<<EOT
		<div class="span3">
			<div class="widget widget">
				<div class="widget-header">
					<h3>Member List </h3>
				</div>
				<div class="widget-content">						
					{$html}
				</div>
			</div>
		</div>
EOT;
	echo $html;
}

function showDetails($details,$month_year,$memberDetails){
	if($details==NULL){
		$html=<<<EOT
			<script>
				$(document).ready(function(){
					$.notify('User Details for the cuurent month is not updated for: {$memberDetails["name"]}','error');
				});
			</script>
EOT;
	echo $html; 
	return;
	}
	$month_year=implode("-",str_split($month_year,4));
	$html=<<<EOT
		<div class="span6">
			<div class="widget widget">
				<div class="widget-header">
					<h3>Details of {$memberDetails["name"]} for: {$month_year} </h3>
				</div>
				<div class="widget-content">						
EOT;
	$breakups=convertObjToArray(json_decode($details["transaction_details"]));
	$html.=<<<EOT
		<fieldset>
			<legend>Summary</legend>
			<table class="table">
				<tr>
					<th>Total Amount Payable For This Month:</th>
					<td>{$details["amount_payable"]}</td>
				</tr>
				<tr>
					<th>Total Amount Payed on this Month:</th>
					<td>{$details["total_amt_payed"]}</td>
				</tr>
				<tr>
					<th>Total Due Left:</th>
					<td>{$details["due_left"]}</td>
				</tr>
				
			</table>
		</fieldset>
EOT;
	if(TRUE){
		$breakups=end($breakups);
	$html.=<<<EOT
EOT;
		$extraAmtHtml="";
		if(isset($breakups["extraAmt"]) && $breakups["extraAmt"]!=0 || $breakups["extraAmt"]!=""){
			$extraAmtHtml=<<<EOT
				<tr>
					<th>Extra Fund Collection</th>
					<td>
						<table>
							<tr>
								<th>Amount</th>
								<td>{$breakups["extraAmt"]}</td>
							</tr>
							<tr>
								<th>Reason</th>
								<td>{$breakups["extraAmtFor"]}</td>
							</tr>
						</table>
					</td>
				</tr>
EOT;
		}
			$html.=<<<EOT
			<fieldset>
				<legend>Payable Amount Break Ups</legend>
				<table class="table">
					<tr>
						<th>Maintenance</th>
						<td>{$breakups["maintenanceAmt"]}</td>
					</tr>
					<tr>
						<th>Previous Dues</th>
						<td>{$breakups["lastMonthDue"]}</td>
					</tr>
					{$extraAmtHtml}
				</table>
			</fieldset>
EOT;
	}
		$m_hstry=convertObjToArray(json_decode($details["monthly_payment_history"]));
		if(isset($m_hstry) && is_array($m_hstry) && count($m_hstry[0])>1){
			$pHhtml="";
			foreach($m_hstry as $v){
				//if(!is_array($v)) continue;
				$pHhtml.=<<<EOT
				<tr>
					<td>{$v["date"]}</td>
					<td>{$v["amountPayed"]}</td>
					<td>{$v["paymentMode"]} </td>
					<td>{$v["paymentType"]}</td>
					<td>{$v["note"]}</td>
				</tr>
EOT;
		}
		$html.=<<<EOT
		<fieldset>
			<legend>Transaction History</legend>
			<table class="table">
				<tr>
					<th>Date</th>
					<th>Amount Payed</th>
					<th>Payment Mode </th>
					<th>Payment Type</th>
					<th>Note</th>
				</tr>
				{$pHhtml}
			</table>
		</fieldset>
EOT;
		}

	$html.=<<<EOT
				</div>
			</div>
		</div>
EOT;
	echo $html;
}

function showMonthPicker($id,$month_year){
	$dt=implode("-",str_split($month_year,4));
	$html=<<<EOT
		<script>
			$(document).ready(function(){
				options={pattern: 'yyyymm'};
				$('#month_picker').monthpicker(options);
				$('#month_picker').change(function(){
					var id="{$id}";
					var ym=$.trim($(this).val());
					location.href="?id="+id+"&month_year="+ym;
					
				});
			
			});
		</script>
		<div class="span3">
			<div class="widget">
				<div class="widget-header">
					<h3>Month Picker </h3>
				</div>
				<div class="widget-content">						
					<input id="month_picker" value={$dt} />
				</div>
			</div>
		</div>
EOT;
	echo $html;

}

function showMemberDetails($memberDetails){
	$fref=md5(MEMBERS);
	$html=<<<EOT
		<style>
			.display{
				margin-top:4px;
			}
		</style>
		<script>
			$(document).ready(function(){
				$(".field").hide();
			});
			function flipFieldAndDisplay(){
				$(".field").toggle();
				$(".display").toggle();
			}
		</script>
		<div class="span3">
			<div class="widget">
				<div class="widget-header">
					<h3>Member Details: {$memberDetails["name"]} </h3>
				</div>
				<div class="widget-content">						
					<form method="POST" class="form form-horizontal ">
						<input type="hidden" name="mem_id" value="{$memberDetails["id"]}" />
						<input type="hidden" name="fref" value="{$fref}" />
						<div class="control-group">	
							
							<label style="width:50px" class="control-label" ><b>Name:</b></label>
							<div style="margin-left:60px" class="controls">
								<div class="field"><input name="data[name]" type="text" class="required span2" id="name" value="{$memberDetails["name"]}" ></div>
								<div style="overflow-x:auto" class="display">{$memberDetails["name"]}</div>	
							</div> <!-- /controls -->				
						</div>
						
						<div class="control-group">											
							<label style="width:50px" class="control-label" ><b>Phone Number:</b></label>
							<div style="margin-left:60px" class="controls">
								<div class="field"><input name="data[ph]"  type="text" class="span2 required" id="ph" value="{$memberDetails["ph"]}" ></div>
								<div class="display">{$memberDetails["ph"]}</div>	
							</div> <!-- /controls -->				
						</div>
						
						<div class="control-group">											
							<label style="width:50px" class="control-label" ><b>Email:</b></label>
							<div style="margin-left:60px" class="controls">
								<div class="field"><input name="data[email]"  type="text" class="span2 required" id="email" value="{$memberDetails["email"]}" ></div>
								<div style="overflow-x:auto" class="display">{$memberDetails["email"]}</div>	
							</div> <!-- /controls -->				
						</div>
						
						<div class="control-group">											
							<label style="width:50px" class="control-label" ><b>Area:</b></label>
							<div style="margin-left:60px" class="controls">
								<div class="field"><input name="data[area]"  type="text" class="span2 required" id="area" value="{$memberDetails["area"]}" ></div>
								<div class="display">{$memberDetails["area"]}</div>	
							</div> <!-- /controls -->				
						</div>
						
						<div class="control-group">											
							<label style="width:50px" class="control-label" ><b>Rate:</b></label>
							<div style="margin-left:60px" class="controls">
								<div class="field"><input name="data[rate]"  type="text" class="span2 required" id="rate" value="{$memberDetails["rate"]}" ></div>
								<div class="display">{$memberDetails["rate"]}</div>	
							</div> <!-- /controls -->				
						</div>
						<div class="control-group">											
							<label style="width:50px" class="control-label" ><b>Concession:</b></label>
							<div style="margin-left:60px" class="controls">
								<div class="field"><input name="data[concession]"  type="text" class="span2 required" id="rate" value="{$memberDetails["concession"]}" ></div>
								<div class="display" style='margin-left:20px;'> {$memberDetails["concession"]}</div>	
							</div> <!-- /controls -->				
						</div>
						<div class="control-group">											
							<label style="width:50px" class="control-label" ></label>
							<div style="margin-left:60px" class="controls">
								<div class="field">
									<input onClick="flipFieldAndDisplay()" value="Cancel" type="button" class="btn btn-primary" />
									<input value="Submit" type="submit" class="btn btn-primary" />
								</div>
								<div class="display"  ><input onClick="flipFieldAndDisplay()" value="Edit" type="button" class="btn btn-primary" /></div>	
							</div> <!-- /controls -->				
						</div>
					</form>
				</div>
			</div>
		</div>
EOT;
	echo $html;
}
function selectMonthForSummary($dt){
	$html=<<<EOT
		<script>
			$(document).ready(function(){
				options={pattern: 'yyyy-mm'};
				$('#month_picker').monthpicker(options);
				$('#month_picker').change(function(){
					var ym=$.trim($(this).val());
					location.href="?month_year="+ym;
					
				});
			
			});
		</script>
		<div class="span3">
			<div class="widget">
				<div class="widget-header">
					<h3>Month Picker </h3>
				</div>
				<div class="widget-content">						
					<input id="month_picker" value={$dt} />
				</div>
			</div>
		</div>
EOT;
	echo $html;

}

function extraCollectionForm(){
	$fref=md5(EXTRA_COLLECTION);
	$html=<<<EOT
		<script>
			$(document).ready(function(){
				options={pattern: 'yyyy-mm'};
				$('#month_picker').monthpicker(options);
			
			});
		</script>
		<form id="make_payment" method="POST" class="form-horizontal">
			<input type="hidden" name="fref" value="{$fref}">
			<fieldset>
				<legend>Details for Extra Collection</legend>
				<div class="control-group">											
					<label class="control-label"> Select Month </label>
					<div class="controls">
						<input for="Select Month" name="data[month_year]" id="month_picker" value="" class="required" />
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label">Enter Amount</label>
					<div class="controls">
						<input for="Collection Amount" name="data[amt]" value="" class="required numeric"/>
					</div>
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label">Reason</label>
					<div class="controls">
						<textarea class="required" name="data[reason]"></textarea>
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
				
				<div class="control-group">											
					<label class="control-label"></label>
					<div class="controls">
						<input type="submit" value="submit">
					</div> <!-- /controls -->													
				</div> <!-- /control-group -->
			</fieldset>
			
		</form>
EOT;
	return $html;
}

?>